package com.yudean.esb.cached;

import com.yudean.esb.domain.esb.EsbDataSource;

import java.util.HashMap;

/**
 * @author : DL<duanlei@gdyd.com>
 * @version : 1.0
 */
public class DataSourcesCollection {
    private static DataSourcesCollection ourInstance = new DataSourcesCollection();
    private static HashMap<String, EsbDataSource> dataSourceHashMap;

    static {
        dataSourceHashMap = new HashMap<String, EsbDataSource>();
    }

    public static DataSourcesCollection getInstance() {
        return ourInstance;
    }

    private DataSourcesCollection() {
    }
    public static void clearDataSourceMap() {

        dataSourceHashMap.clear();
    }
    /**
     * 根据ID获得数据源信息
     *
     * @param datasourceID
     * @return
     */
    public static EsbDataSource getDataSource(String datasourceID) {
        return dataSourceHashMap.get(datasourceID);
    }

    /**
     * 添加数据源配置，如果已经存在则覆盖
     *
     * @param dataSource
     */
    public static void putDataSource(EsbDataSource dataSource) {
        if (dataSource == null) {
            return;
        }
        String key = dataSource.getID();
        dataSourceHashMap.put(key, dataSource);
    }

    /**
     * 删除数据源
     *
     * @param sourceID
     */
    public static void removeDataSource(String sourceID) {
        dataSourceHashMap.remove(sourceID);
    }
}
